package com.gkj.shiro.credentialsMatcher;


import com.gkj.blog.util.PasswordUtil;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

public class RSACredentialsMatcher extends SimpleCredentialsMatcher {
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        UsernamePasswordToken utoken = (UsernamePasswordToken) token;
        //获得用户输入的密码:(rsa加密)
        String inPassword = new String(utoken.getPassword());
        //获得数据库中的密码(rsa加密)
        String dbPassword = (String) info.getCredentials();
        return this.equals(PasswordUtil.decrytByBase64(dbPassword),PasswordUtil.decrytByBase64(inPassword));
    }
}
